package report.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import report.dao.util.ReturnMsgUtil;
import report.dao.vo.tree.TreeVO;
import report.service.tree.ITreeService;

@Controller
public class ReportTreeController {

    @Autowired
    // @Qualifier("test")
    private ITreeService treeService;
    // 获取report目录树
    @RequestMapping(value = "/report/catalog/all")
    @ResponseBody
    public ReturnMsgUtil query() {
        ReturnMsgUtil res = new ReturnMsgUtil();
        res.setContent( treeService.getTree() );
        res.setStatus("success");
        return res;
    }

    // 添加目录
    @PostMapping(value = "/report/catalog/create")
    @ResponseBody
    public ReturnMsgUtil createCata(@RequestBody TreeVO form){
        ReturnMsgUtil res = new ReturnMsgUtil();
        res.setContent( treeService.createCata(form.getPid(),form.getName(),"folder") );
        res.setStatus("success");
        return res;
    }


    // 更新目录
    @PutMapping(value = "/report/catalog/update/{id}")
    @ResponseBody
    public ReturnMsgUtil updateCata(@PathVariable String id, @RequestBody TreeVO form){
        ReturnMsgUtil res = new ReturnMsgUtil();
        res.setContent( treeService.updateCata(id, form.getPid(),form.getName()) );
        res.setStatus("success");
        return res;
    }

    // 删除目录
    @DeleteMapping(value = "/report/catalog/delete/{id}")
    @ResponseBody
    public ReturnMsgUtil deleteCata(@PathVariable String id){
        ReturnMsgUtil res = new ReturnMsgUtil();
        res.setContent( treeService.deleteCata(id));
        res.setStatus("success");
        return res;
    }


}
